package com.ruoyi.report_sh.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.syrw.annotation.FIllBasicInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.ruoyi.report_sh.domain.bo.ReportShShyxyhghyhmhljlbBsInfoBo;
import com.ruoyi.report_sh.domain.vo.ReportShShyxyhghyhmhljlbBsInfoVo;
import com.ruoyi.report_sh.domain.ReportShShyxyhghyhmhljlbBsInfo;
import com.ruoyi.report_sh.mapper.ReportShShyxyhghyhmhljlbBsInfoMapper;
import com.ruoyi.report_sh.service.IReportShShyxyhghyhmhljlbBsInfoService;

import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 石灰有效氧化钙和氧化镁含量试验检测记录Service业务层处理
 *
 * @author llb
 * @date 2024-09-04
 */
@RequiredArgsConstructor
@Service
public class ReportShShyxyhghyhmhljlbBsInfoServiceImpl implements IReportShShyxyhghyhmhljlbBsInfoService {

    private final ReportShShyxyhghyhmhljlbBsInfoMapper baseMapper;

    /**
     * 查询石灰有效氧化钙和氧化镁含量试验检测记录
     */
    @Override
    @FIllBasicInfo
    public ReportShShyxyhghyhmhljlbBsInfoVo queryById(Long excelId){
        return baseMapper.selectVoById(excelId);
    }

    /**
     * 查询石灰有效氧化钙和氧化镁含量试验检测记录列表
     */
    @Override
    public TableDataInfo<ReportShShyxyhghyhmhljlbBsInfoVo> queryPageList(ReportShShyxyhghyhmhljlbBsInfoBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<ReportShShyxyhghyhmhljlbBsInfo> lqw = buildQueryWrapper(bo);
        Page<ReportShShyxyhghyhmhljlbBsInfoVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询石灰有效氧化钙和氧化镁含量试验检测记录列表
     */
    @Override
    public List<ReportShShyxyhghyhmhljlbBsInfoVo> queryList(ReportShShyxyhghyhmhljlbBsInfoBo bo) {
        LambdaQueryWrapper<ReportShShyxyhghyhmhljlbBsInfo> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<ReportShShyxyhghyhmhljlbBsInfo> buildQueryWrapper(ReportShShyxyhghyhmhljlbBsInfoBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<ReportShShyxyhghyhmhljlbBsInfo> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getTotalPage() != null, ReportShShyxyhghyhmhljlbBsInfo::getTotalPage, bo.getTotalPage());
        lqw.eq(bo.getPage() != null, ReportShShyxyhghyhmhljlbBsInfo::getPage, bo.getPage());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancdwmc()), ReportShShyxyhghyhmhljlbBsInfo::getJiancdwmc, bo.getJiancdwmc());
        lqw.eq(StringUtils.isNotBlank(bo.getJilbh()), ReportShShyxyhghyhmhljlbBsInfo::getJilbh, bo.getJilbh());
        lqw.eq(StringUtils.isNotBlank(bo.getGongcmc()), ReportShShyxyhghyhmhljlbBsInfo::getGongcmc, bo.getGongcmc());
        lqw.eq(StringUtils.isNotBlank(bo.getGongcbwyt()), ReportShShyxyhghyhmhljlbBsInfo::getGongcbwyt, bo.getGongcbwyt());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpmc()), ReportShShyxyhghyhmhljlbBsInfo::getYangpmc, bo.getYangpmc());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpbh()), ReportShShyxyhghyhmhljlbBsInfo::getYangpbh, bo.getYangpbh());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpsl()), ReportShShyxyhghyhmhljlbBsInfo::getYangpsl, bo.getYangpsl());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpzt()), ReportShShyxyhghyhmhljlbBsInfo::getYangpzt, bo.getYangpzt());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpsj()), ReportShShyxyhghyhmhljlbBsInfo::getYangpsj, bo.getYangpsj());
        lqw.eq(StringUtils.isNotBlank(bo.getShiyjcrq()), ReportShShyxyhghyhmhljlbBsInfo::getShiyjcrq, bo.getShiyjcrq());
        lqw.eq(StringUtils.isNotBlank(bo.getShiytjwd()), ReportShShyxyhghyhmhljlbBsInfo::getShiytjwd, bo.getShiytjwd());
        lqw.eq(StringUtils.isNotBlank(bo.getShiytjsd()), ReportShShyxyhghyhmhljlbBsInfo::getShiytjsd, bo.getShiytjsd());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancyj()), ReportShShyxyhghyhmhljlbBsInfo::getJiancyj, bo.getJiancyj());
        lqw.eq(StringUtils.isNotBlank(bo.getPandyj()), ReportShShyxyhghyhmhljlbBsInfo::getPandyj, bo.getPandyj());
        lqw.eq(StringUtils.isNotBlank(bo.getZhuyyqsbmcjbh()), ReportShShyxyhghyhmhljlbBsInfo::getZhuyyqsbmcjbh, bo.getZhuyyqsbmcjbh());
        lqw.eq(bo.getTansnzl1() != null, ReportShShyxyhghyhmhljlbBsInfo::getTansnzl1, bo.getTansnzl1());
        lqw.eq(bo.getTansnzl2() != null, ReportShShyxyhghyhmhljlbBsInfo::getTansnzl2, bo.getTansnzl2());
        lqw.eq(bo.getV11() != null, ReportShShyxyhghyhmhljlbBsInfo::getV11, bo.getV11());
        lqw.eq(bo.getV12() != null, ReportShShyxyhghyhmhljlbBsInfo::getV12, bo.getV12());
        lqw.eq(bo.getV21() != null, ReportShShyxyhghyhmhljlbBsInfo::getV21, bo.getV21());
        lqw.eq(bo.getV22() != null, ReportShShyxyhghyhmhljlbBsInfo::getV22, bo.getV22());
        lqw.eq(bo.getV1() != null, ReportShShyxyhghyhmhljlbBsInfo::getV1, bo.getV1());
        lqw.eq(bo.getV2() != null, ReportShShyxyhghyhmhljlbBsInfo::getV2, bo.getV2());
        lqw.eq(bo.getN1() != null, ReportShShyxyhghyhmhljlbBsInfo::getN1, bo.getN1());
        lqw.eq(bo.getN2() != null, ReportShShyxyhghyhmhljlbBsInfo::getN2, bo.getN2());
        lqw.eq(bo.getPingjmend() != null, ReportShShyxyhghyhmhljlbBsInfo::getPingjmend, bo.getPingjmend());
        lqw.eq(bo.getShihzl1() != null, ReportShShyxyhghyhmhljlbBsInfo::getShihzl1, bo.getShihzl1());
        lqw.eq(bo.getShihzl2() != null, ReportShShyxyhghyhmhljlbBsInfo::getShihzl2, bo.getShihzl2());
        lqw.eq(bo.getV31() != null, ReportShShyxyhghyhmhljlbBsInfo::getV31, bo.getV31());
        lqw.eq(bo.getV32() != null, ReportShShyxyhghyhmhljlbBsInfo::getV32, bo.getV32());
        lqw.eq(bo.getV41() != null, ReportShShyxyhghyhmhljlbBsInfo::getV41, bo.getV41());
        lqw.eq(bo.getV42() != null, ReportShShyxyhghyhmhljlbBsInfo::getV42, bo.getV42());
        lqw.eq(bo.getV51() != null, ReportShShyxyhghyhmhljlbBsInfo::getV51, bo.getV51());
        lqw.eq(bo.getV52() != null, ReportShShyxyhghyhmhljlbBsInfo::getV52, bo.getV52());
        lqw.eq(bo.getX1() != null, ReportShShyxyhghyhmhljlbBsInfo::getX1, bo.getX1());
        lqw.eq(bo.getX2() != null, ReportShShyxyhghyhmhljlbBsInfo::getX2, bo.getX2());
        lqw.eq(bo.getPingjz() != null, ReportShShyxyhghyhmhljlbBsInfo::getPingjz, bo.getPingjz());
        lqw.eq(StringUtils.isNotBlank(bo.getFujsm()), ReportShShyxyhghyhmhljlbBsInfo::getFujsm, bo.getFujsm());
        lqw.eq(StringUtils.isNotBlank(bo.getJianc()), ReportShShyxyhghyhmhljlbBsInfo::getJianc, bo.getJianc());
        lqw.eq(StringUtils.isNotBlank(bo.getJil()), ReportShShyxyhghyhmhljlbBsInfo::getJil, bo.getJil());
        lqw.eq(StringUtils.isNotBlank(bo.getFuh()), ReportShShyxyhghyhmhljlbBsInfo::getFuh, bo.getFuh());
        lqw.eq(StringUtils.isNotBlank(bo.getRiq()), ReportShShyxyhghyhmhljlbBsInfo::getRiq, bo.getRiq());
        lqw.eq(StringUtils.isNotBlank(bo.getShebIds()), ReportShShyxyhghyhmhljlbBsInfo::getShebIds, bo.getShebIds());
        lqw.eq(StringUtils.isNotBlank(bo.getPandyjIds()), ReportShShyxyhghyhmhljlbBsInfo::getPandyjIds, bo.getPandyjIds());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancyjIds()), ReportShShyxyhghyhmhljlbBsInfo::getJiancyjIds, bo.getJiancyjIds());
        return lqw;
    }

    /**
     * 新增石灰有效氧化钙和氧化镁含量试验检测记录
     */
    @Override
    @DSTransactional
    public Boolean insertByBo(ReportShShyxyhghyhmhljlbBsInfoBo bo) {
        ReportShShyxyhghyhmhljlbBsInfo add = BeanUtil.toBean(bo, ReportShShyxyhghyhmhljlbBsInfo.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setExcelId(add.getExcelId());
        }
        return flag;
    }

    /**
     * 修改石灰有效氧化钙和氧化镁含量试验检测记录
     */
    @Override
    @DSTransactional
    public Boolean updateByBo(ReportShShyxyhghyhmhljlbBsInfoBo bo) {
        ReportShShyxyhghyhmhljlbBsInfo update = BeanUtil.toBean(bo, ReportShShyxyhghyhmhljlbBsInfo.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(ReportShShyxyhghyhmhljlbBsInfo entity){
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 批量删除石灰有效氧化钙和氧化镁含量试验检测记录
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }
}
